<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>找回密码</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <!--weui.min.css-->
    <link rel="stylesheet" href="/static/index/css/page/base.css"/>
    <link rel="stylesheet" href="/static/index/css/page/font.css"/>
    <link rel="stylesheet" type="text/css" href="/static/index/jquery_weui/lib/weui.min.css">
    <!--jquery-weui.min.css-->
    <link rel="stylesheet" type="text/css" href="/static/index/jquery_weui/css/jquery-weui.min.css">
    <link rel="stylesheet" href="/static/index/css/page/login.css" />

</head>
<body>
<div class="pageControl wallet bg-f5">
    <!--主体-->
    <div class="main">
        <div class="bg-di"></div>
        <div class="msui_nav msui_navTop">
            <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
            <h1 class="msui_navTop-title">找回密码</h1>
        </div>
    </div>
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd">
            <label class="weui-label">手机号</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input tel" type="tel" placeholder="请输入注册使用的手机号">
        </div>
        <div class="weui-cell__ft">
            <button class="weui-vcode-btn get_code">获取验证码</button>
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">验证码</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input yzm" placeholder="请输入短信验证码">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">新密码</label></div>
        <div class="weui-cell__bd">
            <input type="password" class="weui-input new_pwd" placeholder="请输入新密码">
        </div>
    </div>
    <a href="javascript:;" class="weui-btn weui-btn_primary submit">确认找回</a>
</div>
<!-- jquery-2.1.4 -->
<script type="text/javascript" src="/static/index/jquery_weui/lib/jquery-2.1.4.js"></script>
<!-- jquery-weui.min.js -->
<script type="text/javascript" src="/static/index/jquery_weui/js/jquery-weui.min.js"></script>
<script>
    function verifyCode(target,time,mtarget,message) {
        if (time == 0) {
            target.removeAttr('disabled');
            target.html('获取验证码');
            if (mtarget) {
                mtarget.closest('p').css('display', 'none');
                mtarget.html(message);
            }
        }else {
            target.attr('disabled', 'disabled');
            target.html(time + 's后可重新获取');
            if (mtarget) {
                mtarget.closest('p').css('display', 'block');
                mtarget.html(message);
            }
            time--;
            setTimeout(function () {
                verifyCode(target, time);
            }, 1000)
        }
    }

    $('.get_code').on('click',function () {
        var tel = $('.tel').val();
        $.post(
            '/index/login/is_have',
            {tel:tel},
            function (data) {
                if(data.code == -1){
                    alert(data.msg);
                }else if(data.code == 200){
                        /*验证手机号码*/
                        var re;
                        var tel=$(".tel").val();
                        re= /^0?(13|14|15|17|18)[0-9]{9}$/
                        if(re.test(tel))
                        {
                            $.post(
                                "/index/sms/forget_pwd",
                                {tel: tel},
                                function(data){

                                }
                            );
                            verifyCode($('.get_code'),60);
                        }else{
                            alert('请输入正确的手机号码！');
                        }
                }
            },'json'
        )
    })

    $('.submit').on('click',function () {
        var tel = $('.tel').val();
        var yzm = $('.yzm').val();
        var new_pwd = $('.new_pwd').val();
        $.post(
            '/index/login/find_pwd',
            {tel:tel,yzm:yzm,new_pwd:new_pwd},
            function (data) {
                if(data.code == 200){
                    alert(data.msg);
                    history.go(-1);
                }else{
                    alert(data.msg);
                }
            },'json'
        )
    })
</script>
</body>
</html>

